﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSelectOneUser : Page
    {
        protected Button butOneDel;
        protected Button butOneSelect;
        protected Button butQuery;
        protected DropDownList DDLDept;
        protected DropDownList DDLUPDept;
        protected HtmlForm frmuser;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labSelectedUserTip;
        protected Label labSelectUserTip;
        protected ListBox LBSelect;
        protected ListBox LBSelected;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLDate;
        protected TextBox txtEndDate;
        protected TextBox txtQuery;
        protected TextBox txtStartDate;

        protected void butOneDel_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.LBSelected.SelectedIndex > -1)
            {
                int num2 = 0;
                while (num2 < this.LBSelected.Items.Count)
                {
                    if (this.LBSelected.Items[num2].Selected)
                    {
                        if (this.LBSelect.Items.IndexOf(this.LBSelected.Items[num2]) == -1)
                        {
                            this.LBSelect.Items.Add(this.LBSelected.Items[num2]);
                        }
                        str = str + this.LBSelected.Items[num2].Value + "#";
                    }
                    num2++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num2 = 0; num2 < this.LBSelected.Items.Count; num2++)
                        {
                            if (this.LBSelected.Items[num2].Value == strArray[i])
                            {
                                this.LBSelected.Items.Remove(this.LBSelected.Items[num2]);
                            }
                        }
                    }
                }
            }
            this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butOneSelect_Click(object sender, EventArgs e)
        {
            string str = "";
            if (this.LBSelect.SelectedIndex > -1)
            {
                int num2 = 0;
                while (num2 < this.LBSelect.Items.Count)
                {
                    if (this.LBSelect.Items[num2].Selected && (this.LBSelected.Items.IndexOf(this.LBSelect.Items[num2]) == -1))
                    {
                        this.LBSelected.Items.Clear();
                        this.LBSelected.Items.Add(this.LBSelect.Items[num2]);
                        str = str + this.LBSelect.Items[num2].Value + "#";
                    }
                    num2++;
                }
                string[] strArray = str.Split(new char[] { '#' });
                if (strArray.Length > 1)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (num2 = 0; num2 < this.LBSelect.Items.Count; num2++)
                        {
                            if (this.LBSelect.Items[num2].Value == strArray[i])
                            {
                                this.LBSelect.Items.Remove(this.LBSelect.Items[num2]);
                            }
                        }
                    }
                }
            }
            this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
            this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
        }

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.method_0();
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (this.DDLUPDept.SelectedItem.Value == "0")
                {
                    ListItem item2 = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item2);
                }
                else
                {
                    ListItem item = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item);
                }
            }
        }

        private void method_0()
        {
            string strSql = "";
            if (this.DDLDept.SelectedItem.Value == "0")
            {
                strSql = "select a.UserCode,'['+a.UserCode+']'+a.UserName as UserName  from UserInfo a,DeptInfo b  where a.DeptID=b.ID  and a.flag<>'B'";
            }
            if (this.DDLDept.SelectedItem.Value != "0")
            {
                strSql = "select a.UserCode,'['+a.UserCode+']'+a.UserName as UserName  from UserInfo a,DeptInfo b where a.DeptID=b.ID and (" + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ") and a.flag<>'B'";
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                strSql = strSql + " and (a.UserName like '%" + this.txtQuery.Text.Trim() + "%' or a.UserCode like '%" + this.txtQuery.Text.Trim() + "%' or a.Worker like '%" + this.txtQuery.Text.Trim() + "%' or a.UserGWName like '%" + this.txtQuery.Text.Trim() + "%')";
            }
            if (this.RBLDate.SelectedItem.Value == "B")
            {
                if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
                {
                    strSql = strSql + "  and (a.JoinWorkDate<>'' and a.JoinWorkDate is not null) and (Convert(dateTime,a.JoinWorkDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + "')  and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + "')>=Convert(dateTime,a.JoinWorkDate))";
                }
            }
            else if (!((this.txtStartDate.Text.Trim() != "") ? !(this.txtEndDate.Text.Trim() != "") : true))
            {
                strSql = strSql + "  and (a.UserAge<>'' and a.UserAge is not null) and (Convert(dateTime,a.UserAge)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + "')  and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + "')>=Convert(dateTime,a.UserAge))";
            }
            strSql = strSql + " order by a.UserCode";
            this.LBSelect.Items.Clear();
            this.LBSelect.DataTextField = "UserName";
            this.LBSelect.DataValueField = "UserCode";
            this.LBSelect.DataSource = this.publicFun_0.RetrunDataView(strSql);
            this.LBSelect.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (base.Request["ID"] == null)
                {
                    this.int_0 = 0;
                }
                else
                {
                    this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                }
                if (!base.IsPostBack)
                {
                    try
                    {
                        this.DDLUPDept.DataTextField = "DeptName";
                        this.DDLUPDept.DataValueField = "ID";
                        if (!(this.httpCookie_2.Value == "C"))
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + " order by SortInfo,ID");
                        }
                        else
                        {
                            this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                        }
                        this.DDLUPDept.DataBind();
                        if (this.httpCookie_2.Value == "C")
                        {
                            this.DDLUPDept.SelectedIndex = -1;
                            this.DDLDept.SelectedIndex = -1;
                            ListItem item3 = new ListItem("--所有单位--", "0");
                            ListItem item4 = new ListItem("--所有部门--", "0");
                            this.DDLDept.Items.Insert(0, item4);
                            this.DDLUPDept.Items.Insert(0, item3);
                        }
                        else
                        {
                            this.DDLDept.Items.Clear();
                            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                            if (this.DDLDept.Items.Count == 0)
                            {
                                ListItem item2 = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                this.DDLDept.Items.Add(item2);
                            }
                        }
                        this.method_0();
                        if (this.int_0 != 0)
                        {
                            this.LBSelected.Items.Clear();
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand("select b.UserName,a.Manager from ForumType a,UserInfo b where a.Manager=b.UserCode and a.ID=" + this.int_0, connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                ListItem item = new ListItem(reader["UserName"].ToString(), reader["Manager"].ToString());
                                this.LBSelected.Items.Add(item);
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                        }
                        this.labSelectUserTip.Text = "待选人员<font color=red>(" + this.LBSelect.Items.Count + ")</font>";
                        this.labSelectedUserTip.Text = "已选人员<font color=red>(" + this.LBSelected.Items.Count + ")</font>";
                    }
                    catch
                    {
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

